package org.xx.armory.swing.builders;

import org.xx.armory.objectparser.LineInfo;
import org.xx.armory.objectparser.ParsedObject;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.apache.commons.lang3.StringUtils.trimToEmpty;

/**
 * 用户界面模型。
 */
public class UIModel
        extends ParsedObject {
    private final String resourceName;
    private final String title;
    private final int width;
    private final int height;
    private final Map<String, String> messages;
    private final List<ImageModel> images;
    private final List<OptionsModel> options;
    private final List<String> standardActions;
    private final List<ActionModel> actions;
    private final List<MenuBarModel> menuBars;
    private final List<ToolBarModel> toolBars;
    private final List<ComponentModel> components;
    private final String icon;
    private int margin;

    /**
     * 构造一个空的用户界面模型，此模型不包含任何数据。
     */
    public UIModel() {
        this(LineInfo.UNKNOWN, null, null, 0, 0, null, 0, null, null, null, null, null, null, null, null);
    }

    /**
     * 创建用户界面模型。
     *
     * @param lineInfo
     *         源文件中的位置信息。
     * @param resourceName
     *         资源名称。
     * @param title
     *         标题。
     * @param width
     *         宽度。
     * @param height
     *         高度。
     * @param icon
     *         关联的图标。
     * @param margin
     *         内部空白区域尺寸。
     * @param messages
     *         消息文本集合。
     * @param images
     *         图像集合。
     * @param options
     *         选项列表集合。
     * @param standardActions
     *         标准Action集合。
     * @param actions
     *         Action集合。
     * @param menuBars
     *         菜单集合。
     * @param toolBars
     *         工具栏集合。
     * @param components
     *         布局集合。
     */
    public UIModel(
            LineInfo lineInfo,
            String resourceName,
            String title,
            int width,
            int height,
            String icon,
            int margin,
            Map<String, String> messages,
            Collection<? extends ImageModel> images,
            Collection<? extends OptionsModel> options,
            Collection<String> standardActions,
            Collection<? extends ActionModel> actions,
            Collection<? extends MenuBarModel> menuBars,
            Collection<? extends ToolBarModel> toolBars,
            Collection<? extends ComponentModel> components
    ) {
        super(lineInfo);

        this.resourceName = trimToEmpty(resourceName);
        this.title = trimToEmpty(title);
        this.width = width;
        this.height = height;
        this.icon = trimToEmpty(icon);
        this.margin = margin;
        this.messages = messages != null ? new HashMap<>(messages) : Collections.emptyMap();
        this.images = images != null ? new ArrayList<>(images) : Collections.emptyList();
        this.options = options != null ? new ArrayList<>(options) : Collections.emptyList();
        this.standardActions = standardActions != null ? new ArrayList<>(standardActions) : Collections.emptyList();
        this.actions = actions != null ? new ArrayList<>(actions) : Collections.emptyList();
        this.menuBars = menuBars != null ? new ArrayList<>(menuBars) : Collections.emptyList();
        this.toolBars = toolBars != null ? new ArrayList<>(toolBars) : Collections.emptyList();
        this.components = components != null ? new ArrayList<>(components) : Collections.emptyList();
    }

    public final String getResourceName() {
        return this.resourceName;
    }

    public final int getWidth() {
        return this.width;
    }

    public final int getHeight() {
        return this.height;
    }

    public final String getTitle() {
        return this.title;
    }

    public final String getIcon() {
        return this.icon;
    }

    public final int getMargin() {
        return this.margin;
    }

    public final Map<String, String> getMessages() {
        return Collections.unmodifiableMap(this.messages);
    }

    public final List<ImageModel> getImages() {
        return Collections.unmodifiableList(this.images);
    }

    public final List<OptionsModel> getOptions() {
        return Collections.unmodifiableList(this.options);
    }

    public final List<String> getStandardActions() {
        return Collections.unmodifiableList(this.standardActions);
    }

    public final List<ActionModel> getActions() {
        return Collections.unmodifiableList(this.actions);
    }

    public final List<MenuBarModel> getMenuBars() {
        return Collections.unmodifiableList(this.menuBars);
    }

    public final List<ToolBarModel> getToolBars() {
        return Collections.unmodifiableList(this.toolBars);
    }

    public final List<ComponentModel> getComponents() {
        return Collections.unmodifiableList(this.components);
    }
}
